-
-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic annotation of type signatures #7130
Conversation
f03b305
to
387c509
Compare
buffer | ||
} | ||
|
||
pub fn annotation_edits( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've exposed this and annotations_edit() publicly to be used in the language server but It feels weird to expose them from the cli crate. If it should be in another crate what one?
crates/cli/src/main.rs
Outdated
|
||
let annotate_exit_code = match annotate_file(&arena, roc_file_path.to_owned()) { | ||
Ok(()) => 0, | ||
Err(LoadingProblem::FormattedReport(report)) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a problem loading the file then it just prints out the error. I know this needs to be updated but I'm not sure what the error message should be. Should it include the loading problem or just say that there was one?
I've added some comments on the code with some questions about things that I'm not sure about
|
Thank you for your contribution! Sometimes PRs end up staying open for a long time without activity, which can make the list of open PRs get long and time-consuming to review. To keep things manageable for reviewers, this bot automatically closes PRs that haven’t had activity in 60 days. This PR hasn’t had activity in 30 days, so it will be automatically closed if there is no more activity in the next 30 days. Keep in mind that PRs marked |
387c509
to
acea61b
Compare
This has been open long enough so I've put it up for review. There's still issues with suffixed expressions from #7126 but the code for this is independent from that. |
acea61b
to
d4e558d
Compare
I changed an if to an assert last minute 🙃. That should fix it |
@snobee -- can you please merge latest main? Apologies for leaving it so long... I think this slipped through and got forgotten about. |
@lukewilliamboswell No problem 😃 Should be ready for review now! |
crates/cli/src/format.rs
Outdated
// Generated names for errors start with `#` | ||
.replace('#', ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that if there's an error in the type, don't we want to cancel the operation, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe? These only seem show up when a type doesn't implement an ability it's supposed to. I'm not sure how I'd go about detecting all type errors. I could try looking for
Error
FlexVar(None)
orFlexAbleVar(None, ...)
that show up anywhere except as argumentsFlexVar
orFlexAbleVar
that have names that start with '#'
But that still allows things like List.first(8)
which has the type Result a [ListWasEmpty]
. I'm not sure if that would be counted as an error or not? a
doesn't come from anywhere so maybe that means it is?
This stuff is a bit over my head so maybe I'm missing something but I don't see anything in the codebase for this already
The other way to disallow errors is not from the type but if the code itself has any warnings or errors but that seems a bit heavy handed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a
doesn't come from anywhere so maybe that means it is?
I think (this is not really my area...) that may be fine, and the constraint is that a
needs to be a fresh name (not bound in the outer scope).
Maybe @bhansconnect has more specific advice about how we should be applying types here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would short circuit and break out if there are any errors in types, I think it's too easy to generate wrong annotations otherwise. If the easiest method to implement it is to check if the code has any errors, I think that's fine at this moment in time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an early return for generated annotations that contain type errors. It only handles cases that are explicit errors though (Content::Error
or generated names with #
). So it won't ever generate an incorrect annotation, but it will generate annotations for incorrect code that, when fixed, has a different type. The problem I found with short circuiting on compile errors is that they aren't local to the value being annotated, so it would have to error out on any compile error for the whole program. I think that would make it unusable in practice. Does that all sound good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think[cancelling after any compiler error] would make it unusable in practice.
It's still useful if what you've done is fixed all your errors and you now want to annotate everything.
I guess I don't feel super strongly, but my gut tells me that generating annotations for cases we're not absolutely sure there aren't problems with, is going to cause some users a lot of confusion (i.e. what @ayazhafiz is saying).
This is something we can adjust as we go / if we get feedback tho, so I'm not super concerned.
Heads up, we are planning on merging this tomorrow to avoid potential release breakage, so please wait until then for merging. |
Resolves #7042
I've started with all the logic in analysed_doc but I'll probably end up moving some of it into fmt when I start on that part
I'm making some assumptions here that I wanted to confirm: